import { useMutation, useQuery } from "react-query";
import { useRequest } from "../utils/request";
import { IPage, IPageParams } from "../types";

/**
 * !获取全量法律分类接口
 * @returns
 */
export const useGetlawsTypeAll = () => {
  const request = useRequest<ILawsType[]>();
  return useQuery(["getLawsTypeAll"], () =>
    request("/lawsType/ua/getLawsTypeAll", { data: {} })
  );
};
/**
 * !搜索法律分类接口
 * @returns
 */
export const useGetLawsType = (queryParams: ILawsTypeSearchParams) => {
  const request = useRequest<IPage<ILawsType>>();
  return useQuery(["lawsTypeList", queryParams], () =>
    request("/lawsType/ua/getLawsTypeBySearch", { data: queryParams })
  );
};

/**
 * !添加法律分类接口
 */
export const useAddLawsType = () => {
  const request = useRequest<string>();
  return useMutation(async (params: IAddLawsType) => {
    const result = request("/lawsType/addLawsType", {
      data: params,
      method: "PUT",
    });
    return result;
  });
};

/**
 * !修改法律分类接口
 */

export const useUpdateLawsType = () => {
  const request = useRequest<string>();
  return useMutation(async (params: ILawsType) => {
    const result = request("/lawsType/updateLawsTypeById", {
      data: params,
      method: "POST",
    });
    return result;
  });
};

/**
 * !删除法律分类接口
 */
export const useDeletedlawsType = () => {
  const request = useRequest<string>();
  return useMutation(async (params: { lawsTypeId: number }) => {
    const result = request("/lawsType/deletedLawsTypeById", {
      data: params,
      method: "DELETE",
    });
    return result;
  });
};

export type IAddLawsType = {
  lawsTypeName: string;
};

/**
 * 搜索法律分类参数
 */
export type ILawsTypeSearchParams = {
  lawsTypeName: string;
} & IPageParams;

export type ILawsType = {
  /**
   * 法律分类ID
   */
  lawsTypeId: number;

  /**
   * 法律分类类型名称
   */
  lawsTypeName: string;
};
